package com.hy.heath.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hy.heath.common.BusinessException;
import com.hy.heath.mapper.DoctorMapper;
import com.hy.heath.pojo.entity.Doctor;
import com.hy.heath.service.DoctorService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class DoctorServiceImpl extends ServiceImpl<DoctorMapper, Doctor> implements DoctorService {

    @Override
    public List<Doctor> listByDepartment(String department) {
        validateStringParam(department, "科室名称");
        return this.list(new LambdaQueryWrapper<Doctor>()
                .eq(Doctor::getDepartment, department));
    }

    @Override
    public List<Doctor> listByHospital(String hospital) {
        validateStringParam(hospital, "医院名称");
        return this.list(new LambdaQueryWrapper<Doctor>()
                .eq(Doctor::getHospital, hospital));
    }

    @Override
    public List<Doctor> listByTitle(String title) {
        validateStringParam(title, "职称");
        return this.list(new LambdaQueryWrapper<Doctor>()
                .eq(Doctor::getTitle, title));
    }

    // 公共参数校验方法
    private void validateStringParam(String param, String fieldName) {
        if (!StringUtils.hasText(param)) {
            throw new BusinessException(fieldName + "不能为空");
        }
    }
}